package com.buer.storage.api;

import com.buer.storage.business.dto.CorderDto;
import com.buer.storage.business.dto.CorderStorageDto;
import com.buer.storage.business.dto.StockDto;
import com.buer.storage.business.service.CorderService;
import com.buer.storage.common.annotation.Auth;
import com.buer.storage.common.eumn.ResultEnum;
import com.buer.storage.common.utils.BaseResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/corder")
public class CorderController {
    @Resource
    private CorderService crderService;

    //增加盘点单所有信息
    @Auth
    @PostMapping("/insertCorder.do")
    public BaseResult insert(@RequestBody CorderStorageDto corderStorageDto){
        System.out.println(corderStorageDto);
        if (crderService.insertCorder(corderStorageDto) > 0) {
            //盘点单保存成功
            return BaseResult.build(ResultEnum.SUCCESS);
        }
        //盘点单保存失败
        return BaseResult.build(ResultEnum.FAILURE);
    }

    //根据盘点单ID查询盘点单信息
    @Auth
    @GetMapping("/findCorderAllById.do")
    public BaseResult findCorderAllById(Integer checkId){
        List<CorderStorageDto> corderAllById = crderService.findCorderAllById(checkId);
        return BaseResult.build(ResultEnum.SUCCESS,corderAllById);
    }

    //查询所有盘点单信息
    @Auth
    @GetMapping("/findCorderAll")
    public BaseResult findCorderAll(){
        List<CorderDto> corderAll = crderService.findCorderAll();
        return BaseResult.build(ResultEnum.SUCCESS,corderAll);
    }

    //根据盘点单ID删除盘点单信息
    @Auth
    @GetMapping("/deleteCorderAllById")
    public BaseResult deleteCorderAllById(Integer checkId){
        if(crderService.deleteCorderAllById(checkId)>0){
            //删除盘点单成功
            return BaseResult.build(ResultEnum.SUCCESS);
        }
        //删除盘点单失败
        return BaseResult.build(ResultEnum.FAILURE);
    }

    //更新盘点单信息
    @Auth
    @PostMapping("/updateCorderdetails.do")
    public BaseResult updateCorderdetails(@RequestBody CorderStorageDto corderStorageDto) {
        if (crderService.updateCorderdetails(corderStorageDto) > 0) {
            //更新盘点单成功
            return BaseResult.build(ResultEnum.SUCCESS);
        }
        //更新盘点单失败
        return BaseResult.build(ResultEnum.FAILURE);
    }

    @Auth
    @GetMapping("/findStockByWarehouseId")
    public BaseResult findStockByWarehouseId(Integer warehouoseId){
        List<StockDto> stockByWarehouseId = crderService.findStockByWarehouseId(warehouoseId);
        return BaseResult.build(ResultEnum.SUCCESS,stockByWarehouseId);
    }

    @Auth
    @GetMapping("/findStockByProdArea")
    public BaseResult findStockByProdArea(Integer prodArea,Integer warehouseId){
        List<StockDto> stockByprodArea = crderService.findStockByProdArea(prodArea,warehouseId);
        return BaseResult.build(ResultEnum.SUCCESS,stockByprodArea);
    }

    @Auth
    @GetMapping("/findStockByProdDepart")
    public BaseResult findStockByProdDepart(Integer prodDepart,Integer prodArea,Integer warehouseId){
        List<StockDto> stockByprodDepart = crderService.findStockByProdDepart(prodDepart,prodArea,warehouseId);
        return BaseResult.build(ResultEnum.SUCCESS,stockByprodDepart);
    }

    @Auth
    @GetMapping("/searchStock")
    public BaseResult searchStock(String prodCode,String prodName,Integer prodArea,Integer prodDepart){
        List<StockDto> stockDtos = crderService.searchStock(prodCode, prodName, prodArea, prodDepart);
        return BaseResult.build(ResultEnum.SUCCESS,stockDtos);
    }

}
